package clueless.server;

import static org.junit.Assert.*;

import org.junit.Test;

import clueless.utilities.Card;
import clueless.utilities.Character;
import clueless.utilities.Connection;
import clueless.utilities.Map;
import clueless.utilities.Room;
import clueless.utilities.Weapon;

public class PlayerTest {

	@Test
	public void testInitPlayerLocation() {
		Map map = new Map();
		
		Player mrGreen = new Player(Character.m_MR_GREEN, new Connection());
		mrGreen.setStartingRoom(map);
		assertEquals(mrGreen.getRoom(), map.getConservatory().getRightRoom());
		
		Player mrsWhite = new Player(Character.m_MRS_WHITE, new Connection());
		mrsWhite.setStartingRoom(map);
		assertEquals(mrsWhite.getRoom(), map.getBallroom().getRightRoom());
		
		Player mrsPeakcock = new Player(Character.m_MRS_PEACOCK, new Connection());
		mrsPeakcock.setStartingRoom(map);
		assertEquals(mrsPeakcock.getRoom(), map.getConservatory().getUpRoom());
		
		Player profPlum = new Player(Character.m_PROF_PLUM, new Connection());
		profPlum.setStartingRoom(map);
		assertEquals(profPlum.getRoom(), map.getLibrary().getUpRoom());
		
		Player msScarlet = new Player(Character.m_MISS_SCARLET, new Connection());
		msScarlet.setStartingRoom(map);
		assertEquals(msScarlet.getRoom(), map.getLounge().getLeftRoom());
		
		Player colMustart = new Player(Character.m_COL_MUSTARD, new Connection());
		colMustart.setStartingRoom(map);
		assertEquals(colMustart.getRoom(), map.getLounge().getDownRoom());
	}
	
	@Test
	public void testPlayerPossibleMoves() {
		Map map = new Map();
		
		Player mrGreen = new Player(Character.m_MR_GREEN, new Connection());
		mrGreen.setStartingRoom(map);
		assertEquals(mrGreen.getPossibleMoves(null), "Left,Right,");
		
		mrGreen.setRoom(Room.m_BILLIARD_ROOM, map);
		assertEquals(mrGreen.getPossibleMoves(null), "Up,Down,Left,Right,");
		
		mrGreen.setRoom(Room.m_LOUNGE, map);
		assertEquals(mrGreen.getPossibleMoves(null), "Down,Left,Secret,");
	}
	
	@Test
	public void testPlayerMove() {
		Map map = new Map();
		
		Player mrGreen = new Player(Character.m_MR_GREEN, new Connection());
		mrGreen.setStartingRoom(map);
		
		assertFalse(mrGreen.move("Down"));
		
		assertTrue(mrGreen.move("RIGHT"));
		assertEquals(mrGreen.getRoom(),map.getBallroom());
		
		assertTrue(mrGreen.move("up"));
		assertTrue(mrGreen.move("UP"));
		assertEquals(mrGreen.getRoom(),map.getBillardRoom());
		
		assertTrue(mrGreen.move("left"));
		assertTrue(mrGreen.move("LEFT"));
		assertEquals(mrGreen.getRoom(),map.getLibrary());
		
		assertTrue(mrGreen.move("DOWN"));
		assertTrue(mrGreen.move("down"));
		assertEquals(mrGreen.getRoom(),map.getConservatory());
		
		assertTrue(mrGreen.move("SECRET"));
		assertEquals(mrGreen.getRoom(),map.getLounge());
	}
	
	@Test
	public void testPlayerInRoom() {
		Map map = new Map();
		
		Player mrGreen = new Player(Character.m_MR_GREEN, new Connection());
		mrGreen.setStartingRoom(map);
		
		assertFalse(mrGreen.inRoom());
		mrGreen.move("RIGHT");
		assertTrue(mrGreen.inRoom());
	}	
	
	@Test
	public void testPlayerCards() {
		Player mrGreen = new Player(Character.m_MR_GREEN, new Connection());
		
		mrGreen.addCard(new Card("weapon", Weapon.m_CANDLESTICK));
		mrGreen.addCard(new Card("character", Character.m_MRS_WHITE));
		mrGreen.addCard(new Card("room", Room.m_HALL));
		
		assertEquals(mrGreen.numCards(), 3);
		
		assertEquals(mrGreen.getCards(),Weapon.m_CANDLESTICK.toLowerCase() + "," + Character.m_MRS_WHITE.toLowerCase() + "," + Room.m_HALL.toLowerCase() + ",");
		
		assertTrue(mrGreen.haveCard("CANDLESTICK"));
		assertTrue(mrGreen.haveCard("hall"));
		assertFalse(mrGreen.haveCard("library"));
		
		
	}
}
